Spatial analysis

California oil spills

Overview

This code visualizes and analyzes spatial data of oil spill events in California in 2008, recorded by the California Department of Fish and Wildlife. An interactive map, a chloropleth map, and a g-function plot are created.

Data citation: California Department of Fish and Wildlife, Office of Spill Prevention and Response. 2020. Oil Spill Incident Tracking [ds394]. https://map.dfg.ca.gov/metadata/ds0394.html

Setup

Data input

# read in county shape file
counties_sf <- read_sf(here("data", "CA_Counties_TIGER2016.shp")) %>% 
  janitor::clean_names() %>% 
  select(name)

# read in oil spills shape file, convert to 3857 projection
oil_spills_sf <- read_sf(here("data", "ds394", "ds394.shp")) %>% 
  janitor::clean_names() %>% 
  st_transform(3857)

Interactive map

tmap_mode(mode = "view")
tm_shape(counties_sf) +
  tm_borders(col = "black") +
  tm_shape(oil_spills_sf) +
  tm_dots()

Figure 1. Exploratory, interactive map of oil spill events in California in 2008, along with California counties. Oil spills are concentrated along the coastline and especially in the Los Angeles and San Francisco Bay areas.

Spatial join and summarize

merged <- counties_sf %>% 
  st_join(oil_spills_sf) %>% 
  group_by(name) %>% 
  summarize(spill_count = n())

Static map

ggplot(merged) +
  geom_sf(aes(fill = spill_count)) +
  scale_fill_distiller(palette = "YlOrRd", direction = 1) +
  labs(fill = "Number of oil spills") +
  theme_minimal()

Figure 2. Oil spills in California in 2008 by county. The greatest number of oil spills occurred in Los Angeles County.

Point pattern analysis

spills_sp <- as(oil_spills_sf, "Spatial")

spills_coords <- coordinates(spills_sp)

spills_bbox <- bbox(spills_sp)
spills_win <- owin(xrange = spills_bbox[1,], yrange = spills_bbox[2,])

spills_ppp <- ppp(x = spills_coords[,1], y = spills_coords[,2], window = spills_win)

counties_sp <- as(counties_sf, "Spatial")

counties_bbox <- bbox(counties_sp)
counties_owin <- owin(xrange = counties_bbox[1,], yrange = counties_bbox[2,])

spills_full <- ppp(spills_ppp$x, spills_ppp$y, window = counties_owin)

r_vec <- seq(0, 50000, by = 1000)

gfunction <- envelope(spills_full, fun = Gest, r = r_vec, nsim = 10, nrank = 2)
Generating 10 simulations of CSR  ...
1, 2, 3, 4, 5, 6, 7, 8, 9, 
10.

Done.
gfunction_long <- gfunction %>% 
  as.data.frame() %>% 
  pivot_longer(cols = obs:hi, names_to = "model", values_to = "g_val")

ggplot(data = gfunction_long, aes(x = r, y = g_val, color = model)) +
  geom_line()

Figure 3. G-function plot showing point pattern analysis of oil spill events in California. Oil spill events are spatially clustered compared to complete spatial randomness.